//
//  LCViewController+LCImagesShareUMeng.m
//  JKBiblicalReading
//
//  Created by admin on 2018/8/23.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCViewController+LCImagesShareUMeng.h"
#import <ShareSDK/ShareSDK.h>

@implementation LCViewController (LCImagesShareUMeng)

- (void)lcShareViewDidSelecteBtnWithBtnText:(NSString *)btText imageData:(UIImage *)imageData{
    NSLog(@"---btText-%@",btText);
    SSDKPlatformType platformType = SSDKPlatformSubTypeWechatSession;
    if ([btText isEqualToString:@"分享朋友圈"]) {
        platformType = SSDKPlatformSubTypeWechatTimeline;
    }
    if ([btText isEqualToString:@"分享微信"]) {
        platformType = SSDKPlatformSubTypeWechatSession;
    }
    if ([btText isEqualToString:@"分享QQ"]) {
        platformType = SSDKPlatformSubTypeQQFriend;
    }
    if ([btText isEqualToString:@"分享QQ空间"]) {
        platformType = SSDKPlatformSubTypeQZone;
    }
    if ([btText isEqualToString:@"分享微博"]) {
        platformType = SSDKPlatformTypeSinaWeibo;
    }
    [self shareImageAndTextToPlatformType:platformType imageUrl:nil imageData:imageData];
}

#pragma mark - 分享图片
- (void)shareImageAndTextToPlatformType:(SSDKPlatformType)platformType imageUrl:(NSString *)imageUrl imageData:(UIImage *)imageData{
    if ([ShareSDK isClientInstalled:platformType] == NO) {
        if (SSDKPlatformSubTypeWechatTimeline == platformType ||
            SSDKPlatformSubTypeWechatSession == platformType
            ) {
            [SVProgressHUD showErrorWithStatus:@"未安装微信"];
        }
        return;
    }
    //1、创建分享参数 imageUrl不使用
    NSArray *imageArray = @[imageData];
    
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:nil
                                     images:imageArray
                                        url:nil
                                      title:nil
                                       type:SSDKContentTypeImage];
    //进行分享
    [ShareSDK share:platformType //传入分享的平台类型
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
         NSString *result;
         if (state == SSDKResponseStateCancel) {
             result = [NSString stringWithFormat:@"取消分享!"];
         }else if (state == SSDKResponseStateFail) {
             result = [NSString stringWithFormat:@"分享失败!"];
         }
         if (result != nil) {   [SVProgressHUD showErrorWithStatus:result]; }
     }];
}

/// 获取View的截图
- (UIImage *)screenShotWithView:(UIView *)v {
    UIGraphicsBeginImageContext(v.frame.size);
    [v.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

#pragma mark-动态分享
///动态分享
- (void)shotDynamicShareWithType:(NSString *)type dataImages:(NSArray <UIImage *>*)dataImages success:(void (^)(NSDictionary *))successBlock failure:(void (^)(NSString *))failureBlock  {
    [LSZRequestResolutionDic uploadFilesOfVariousTypes:dataImages filePath:@[[NSDate.new timeStampStr]] :^(BOOL isOK, NSString *string, LSZFileUploadGenericManager *manager) {
        if (isOK) {
            [LSZRequestData releaseTheDynamic:type type:@"" resource:@""  title:@"圣经金句" content:@"" theme:@"" images:manager.idString :^(BOOL isOk, NSString * Str, NSDictionary * dicTion) {
                if (isOK == YES) {
                    if ([Str rangeOfString:@"成功"].location != NSNotFound) {
                        if (successBlock) {
                            successBlock(dicTion);
                        }
                    }
                }else{
                    if (failureBlock) {
                        failureBlock(string);
                    }
                }
            }];
            
        }else{
            if (failureBlock) {
                failureBlock(string);
            }
        }
    }];
}

@end
